Passed
Pull Request — master (#67)
by Michael
02:36
created

paragraphButtons.js ➔ ... ➔ insertParagraph   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 10
nc 1
dl 0
loc 12
rs 9.9
c 0
b 0
f 0
nop 1
1
import { insertParagraphAtPos } from '../customCommands';
2
3
/**
4
 * Attach event handler to buttons for inserting a paragraph
5
 *
6
 * @return {void}
7
 */
8
export function initializeButtons() {
9
    if (window.Prosemirror.paragraphHandlingIsInitialized) {
10
        return;
11
    }
12
    window.Prosemirror.paragraphHandlingIsInitialized = true;
13
    jQuery(document).on('click', '.ProseMirror button.addParagraphButton', function insertParagraph(event) {
14
        event.stopPropagation();
15
        event.preventDefault();
16
        const $button = jQuery(this);
17
        const viewID = $button.data('viewid');
18
        const direction = $button.data('direction');
19
        const view = window.Prosemirror.views[viewID];
20
21
        const pos = view.posAtDOM(event.target.parentNode);
22
        const command = insertParagraphAtPos(pos, direction);
23
        command(view.state, view.dispatch);
24
    });
25
}
26
27
/**
28
 * Produce the spec for a button to insert a paragraph before or after the respective element
29
 *
30
 * @param viewID
31
 * @param direction
32
 * @return {array}
33
 */
34
export function getButtonSpec(viewID, direction) {
35
    if (typeof LANG === 'undefined') {
0 ignored issues
show
Bug introduced by
The variable LANG seems to be never declared. If this is a global, consider adding a /** global: LANG */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
36
        // early return during js schema testing
37
        return [];
38
    }
39
    return [
40
        'button',
41
        {
42
            class: 'addParagraphButton',
43
            type: 'button',
44
            'data-direction': direction,
45
            'data-viewid': viewID,
46
        },
47
        LANG.plugins.prosemirror['button:insert paragraph'],
48
    ];
49
}
50